<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class FgcmsContact {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty) {
		//contructor function
		$this->db = $db;
		$this->smarty = $smarty;
		$this->ConfigBean = new FgcmsConfigBean();
	}
	
	public function view_formcontact() {
		if($_POST['act']=='sendcontact')
		{
			if($_POST['captcha'] == $_SESSION['captcha_str'])
			{
				$this->send_contact_email($_POST);
				header("Location: ?page=contact&act=success");
			}
			else
			$message = "Code falsch eingegeben";	
			$this->smarty->assign('FORM_CONTACT',$_POST);	
			$this->smarty->assign('MESSAGE',$message);	
		}
		if(isset($_GET['act']) && $_GET['act']=='success')
		{
			$page->page_name = "Contact Successful";
			$page->page_content = $this->smarty->fetch('contact_success.tpl');
			$this->smarty->assign('PAGE',$page);	
		}
		else
		{
			$UDS = FgcmsConfigBean::getconfig($this->db,"GOOGLE_UDS_KEY");
			$API = FgcmsConfigBean::getconfig($this->db,"GOOGLE_API_KEY");
			$address = FgcmsConfigBean::getconfig($this->db,"GOOGLE_ADDRESS");
			$this->smarty->assign("GOOGLE_UDS",$UDS->value);
			$this->smarty->assign("GOOGLE_API",$API->value);
			$this->smarty->assign("ADDRESS",$address->value);
			$page->page_name = "Kontaktformular";
			$page->page_content = $this->smarty->fetch('contact.tpl');
			$this->smarty->assign('PAGE',$page);
		}
	}
	
	public function send_contact_email($post){
		$contact_email = $this->ConfigBean->getconfig($this->db,"CONTACT_EMAIL");
		//$to = "info@guncms.de";
		$to = $contact_email->value;
    	$from = $post['email'];
		$reply = $post['email'];
		$subject = "Contact";
		$this->smarty->assign('CONTENT',$post);
		$str = $this->smarty->fetch("email_contact.tpl");
		$message = $str;
		$header = "Content-type: text/html\r\nFrom: $from\r\nReply-to: $reply";
 
		mail($to, $subject, $message, $header); 

	}
}
?>
